﻿namespace MvcScriptManager
{
    using System;
    using System.Web;

    /// <summary>
    /// HttpHandler to output the combined script file.
    /// </summary>
    public class CombineScriptHandler : IHttpHandler
    {
        /// <summary>
        /// Gets a value indicating whether another request can use the <see cref="System.Web.IHttpHandler"/> instance.
        /// </summary>
        /// <returns>Always returns true since this class is stateless..
        /// </returns>
        public bool IsReusable
        {
            get { return true; }
        }

        /// <summary>
        /// Outputs the combined script file.
        /// </summary>
        /// <param name="context">The http context.</param>
        public void ProcessRequest(HttpContext context)
        {
            if (!ScriptManager.OutputCombinedScriptFile(context))
            {
                throw new InvalidOperationException("Combined script file output failed unexpectedly.");
            }
        }
    }
}
